package com.srwl.mytx.fragment;//package com.srbl.mytx.fragment;
//
//import android.content.Intent;
//import android.graphics.Bitmap;
//import android.graphics.Color;
//import android.graphics.Point;
//import android.graphics.drawable.ColorDrawable;
//import android.location.GaodeLocationClient;
//import android.os.Bundle;
//import android.os.Handler;
//import android.support.annotation.NonNull;
//import android.support.annotation.Nullable;
//import android.support.v4.widget.DrawerLayout;
//import android.support.v7.widget.LinearLayoutManager;
//import android.support.v7.widget.RecyclerView;
//import android.support.v7.widget.SearchView;
//import android.support.v7.widget.helper.ItemTouchHelper;
//import android.util.Log;
//import android.view.LayoutInflater;
//import android.view.MotionEvent;
//import android.view.View;
//import android.view.ViewGroup;
//import android.widget.ExpandableListView;
//import android.widget.ImageButton;
//import android.widget.ImageView;
//import android.widget.LinearLayout;
//import android.widget.ProgressBar;
//import android.widget.TextView;
//
//import com.alibaba.fastjson.JSONObject;
//import com.amap.api.maps.AMap;
//import com.amap.api.maps.CameraUpdateFactory;
//
//import com.amap.api.maps.model.MyLocationStyle;
//import com.baidu.location.BDAbstractLocationListener;
//import com.baidu.location.BDLocation;
//import com.baidu.location.LocationClient;
//import com.baidu.location.LocationClientOption;
//import com.baidu.mapapi.SDKInitializer;
//import com.baidu.mapapi.map.BaiduMap;
//import com.baidu.mapapi.map.BitmapDescriptor;
//import com.baidu.mapapi.map.BitmapDescriptorFactory;
//import com.baidu.mapapi.map.InfoWindow;
//import com.baidu.mapapi.map.MapPoi;
//import com.baidu.mapapi.map.MapStatus;
//import com.baidu.mapapi.map.MapStatusUpdate;
//import com.baidu.mapapi.map.MapStatusUpdateFactory;
//import com.baidu.mapapi.map.MapView;
//import com.baidu.mapapi.map.Marker;
//import com.baidu.mapapi.map.MarkerOptions;
//import com.baidu.mapapi.map.MyLocationConfiguration;
//import com.baidu.mapapi.map.MyLocationData;
//import com.baidu.mapapi.map.UiSettings;
//import com.baidu.mapapi.model.LatLng;
//import com.bumptech.glide.Glide;
//import com.bumptech.glide.load.engine.DiskCacheStrategy;
//import com.bumptech.glide.request.RequestOptions;
//import com.bumptech.glide.request.target.SimpleTarget;
//import com.bumptech.glide.request.transition.Transition;
//import com.srwl.mytx.im.MessageReceivedQueue;
//import com.srwl.mytx.utils.DateUtils;
//import com.srwl.mytx.Constant;
//import com.srwl.mytx.EaseConstant;
//import com.srwl.mytx.domain.Contact;
//import com.srwl.mytx.domain.User;
//import com.srwl.mytx.Helper;
//import com.srwl.mytx.R;
//import com.srwl.mytx.RetrofitManager;
//import com.srwl.mytx.activity.ChatActivity;
//import com.srwl.mytx.activity.MainActivity;
//import com.srwl.mytx.activity.PublishTopicActivity;
//import com.srwl.mytx.activity.TopicDetailsActivity;
//import com.srwl.mytx.adapter.SearchHistoryAdapter;
//import com.srwl.mytx.adapter.SearchResultAdapter;
//import com.srwl.mytx.domain.CommonResult;
//import com.srwl.mytx.domain.Topic;
//import com.srwl.mytx.service.TopicService;
//import com.srwl.mytx.utils.PreferenceManager;
//import com.srwl.mytx.widget.ContactListView;
//
//
//import java.text.SimpleDateFormat;
//import java.util.ArrayList;
//import java.util.Calendar;
//import java.util.Date;
//import java.util.HashMap;
//import java.util.List;
//import java.util.Map;
//
//import cn.jmessage.support.qiniu.android.utils.StringUtils;
//import retrofit2.Call;
//import retrofit2.Callback;
//import retrofit2.Response;
//
///**
// * Created by dahai2070 on 2016/8/23 0023.
// */
//public class BaiDuMapFragment extends BaseFragment implements View.OnClickListener, AMap.OnMyLocationChangeListener {
//    private static final String TAG = BaiDuMapFragment.class.getSimpleName();
//
//    private static final int MAKER_HEIGHT = 40;//单位dp
//    private ProgressBar progressBar;
//    private MapView bMapView = null;
//    public BaiduMap mBaiduMap = null;
//    private UiSettings mUiSettings;
//
//    private Marker mMarker;
//    private DrawerLayout mDrawerLayout;
//    private ExpandableListView listView;
//    private ContactListView contactListView;
//    // private ExpandableAdapter adapter;
//    private RecyclerView rl_search;
//    private SearchHistoryAdapter searchHistoryAdapter;
//    private SearchResultAdapter searchResultAdapter;
//    private View view;
//    private ImageButton btnMapstatus;
//
//    private ImageButton btn_publish;
//    private SearchView searchView;
//    protected boolean hidden;
//    private Map<String, List<Contact>> childMap = new HashMap<>();
//    private List<String> parentList = new ArrayList<>();
//    private List<String> searchHistoryList = new ArrayList<>();
//    private List<Topic> searchResultList = new ArrayList<>();
//    private long startTime = 0;
//    private int changeCount = 0;
//    private boolean boL_derectionDown = true;
//    boolean bol_firstChange = true;
//    boolean bol_hasClear;
//    private float oldY = 0;
//    private boolean showSearchResult;
//    private MainActivity.ChangeFragmentListener listener;
//    private LocationClient mLocationClient;
//    private LatLng ll;
//    private LatLng slidell;
//    private MyLocationConfiguration.LocationMode mCurrentMode;
//    private boolean bol_location;
//    private boolean isFirstLocation = true;
//    private double mCurrentLatOld;
//    private static final int INFO_WINDOW_OFF_SET = 50;//单位dp
//    private List<Topic> pushTopicList = new ArrayList<>();
//    //为了让收到的推送主题，在当前页面没有被隐藏的情况下，均匀的显示给用户，
//    private int postDelay = 10000;
//    private boolean isContinue;
//    private Handler handler = new Handler();
//    private Runnable showPushTopic = new Runnable() {
//        @Override
//        public void run() {
//            if (pushTopicList.size() != 0) {
//                showSingleMarker(pushTopicList.remove(0));
//            }
//
//            if (pushTopicList.size() != 0 && !hidden) {
//                isContinue = true;
//                handler.postDelayed(showPushTopic, postDelay);
//            } else {
//                isContinue = false;
//            }
//        }
//    };
//    private boolean bol_needNearbySearch;
//    private float downX;
//    private float downY;
//    private boolean bol_firstSlide;
//    private float lastX;
//    private float lastY;
//    private boolean bol_directionDown = true;
//    private boolean bol_directionRight = true;
//    private final static int SLIDE_CHANGE_DIRECTION_THRESHOLD = 15;//滑动换向检测阈值
//
//
//    @Nullable
//    @Override
//    public View onCreateView(final LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
//        SDKInitializer.initialize(getActivity().getApplicationContext());
//        view = inflater.inflate(R.layout.fragment_bai_du_map, container, false);
//        initContactListView();
//        progressBar = view.findViewById(R.id.progress_bar);
//        mDrawerLayout = view.findViewById(R.id.drawer_layout);
//        initDrawerLayout();
//        btnMapstatus = view.findViewById(R.id.btn_map_status);
//        btn_publish = view.findViewById(R.id.btn_publish);
//        rl_search = view.findViewById(R.id.rl_search);
//        btnMapstatus.setOnClickListener(this);
//        btn_publish.setOnClickListener(this);
//        view.findViewById(R.id.iv_topic_show_model_switch).setOnClickListener(this);
//        initSearchView();
//        return view;
//    }
//
//    @Override
//    public void onActivityCreated(@Nullable Bundle savedInstanceState) {
//        super.onActivityCreated(savedInstanceState);
//        // aMapView = (com.amap.api.maps.MapView) view.findViewById(R.id.aMapView);
//        //  aMapView.onCreate(savedInstanceState);
//
//        initLocation();
//
//    }
//
//    private void initLocation() {
//        bMapView = view.findViewById(R.id.map);
//
//        mBaiduMap = bMapView.getMap();
//
//        mBaiduMap.setCompassPosition(new Point(screenWidth - 100, 100));
////设置缩放级别
//        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.zoomTo(18));
//        mBaiduMap.setOnMapClickListener(new BaiduMap.OnMapClickListener() {
//            @Override
//            public void onMapClick(com.baidu.mapapi.model.LatLng latLng) {
//                // mBaiduMap.clear();
//            }
//
//            @Override
//            public boolean onMapPoiClick(MapPoi mapPoi) {
//                return false;
//            }
//        });
//        MapStatus mapStatus = new MapStatus.Builder(mBaiduMap.getMapStatus()).overlook(-45).build();
//        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatus));
//
//        mLocationClient = new LocationClient(getActivity());     //声明LocationClient类
//        mLocationClient.registerLocationListener(new BDAbstractLocationListener() {
//            @Override
//            public void onReceiveLocation(BDLocation bdLocation) {
//                Log.d(TAG, "onReceiveLocation:收到定位回调 ");
//                receiveLocation(bdLocation);
//            }
//        });    //注册监听函数
//        LocationClientOption option = new LocationClientOption();
//        option.setScanSpan(1000);//0是默认值 金定位一次
//        option.setCoorType("bd09ll");
//        option.setOpenGps(true);
//        option.setLocationMode(LocationClientOption.LocationMode.Hight_Accuracy);
//
//        mLocationClient.setLocOption(option);
//        mBaiduMap.setMyLocationEnabled(true);
//        if (!mLocationClient.isStarted()) {
//            mLocationClient.start();
//        }
//
//        mBaiduMap.setOnMapTouchListener(new BaiduMap.OnMapTouchListener() {
//            @Override
//            public void onTouch(MotionEvent motionEvent) {
//                //用户拖动地图后，不再跟随移动，直到用户点击定位按钮
////                followMove = false;
////                if (!followMove) {
////                    if (myLocationStyle.getMyLocationType() != MyLocationStyle.LOCATION_TYPE_MAP_ROTATE_NO_CENTER) {
////                        //mBaiduMap.setMyLocationStyle(myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_SHOW));
////                        btnMapstatus.setBackgroundResource(R.drawable.tx_map_location);
////                        myLocationStyle.myLocationIcon(BitmapDescriptorFactory.fromResource(R.drawable.compass3));
////                        //btn_trackQuery.setVisibility(View.VISIBLE);
////                        //btnMapstatus.setVisibility(View.INVISIBLE);
////                    } else {
////                        aMap.setMyLocationStyle(myLocationStyle.myLocationType(MyLocationStyle.LOCATION_TYPE_LOCATION_ROTATE_NO_CENTER));
////                    }
////
////                }
//
//                float currentX = motionEvent.getRawX();
//                float currentY = motionEvent.getRawY();
//                switch (motionEvent.getAction()) {
//                    case MotionEvent.ACTION_DOWN:
//                        //如果拖动地图的时候，循环在执行，那么中断循环
//                        if (isContinue) {
//                            handler.removeCallbacks(showPushTopic);
//                        }
//                        startTime = motionEvent.getDownTime();
//                        bol_hasClear = false;
//                        bol_needNearbySearch = false;
//                        downX = motionEvent.getRawX();
//                        downY = motionEvent.getRawY();
//                        break;
//
//                    case MotionEvent.ACTION_MOVE:
//                        if (bol_firstSlide) {//首次进入滑动状态，设置X、Y方向参考点
//                            bol_firstSlide = false;
//                            lastX = currentX;
//                            lastY = currentY;
//                            return;
//                        }
//                        //检测X方向的滑动换向
//                        if (currentX - lastX > 0) {//此刻向右滑动
//                            if (!bol_directionRight) {//发生换向，重置参考点
//                                if (currentX - lastX > SLIDE_CHANGE_DIRECTION_THRESHOLD) {//滑动距离超过阈值，判定为已经换向
//                                    changeCount += 1;
//                                    //  Log.d(TAG, "onTouch: 向右换向" + changeCount);
//                                }
//                                //   lastX = currentX;
//                            }
//                            //设置当前为向右滑动
//                            bol_directionRight = true;
//
//                        } else if (currentX - lastX < 0) {//此刻向左边滑动
//
//                            if (bol_directionRight) {//发生换向，重置参考点
//                                if (Math.abs(currentX - lastX) > SLIDE_CHANGE_DIRECTION_THRESHOLD) {//滑动距离超过阈值，判定为已经换向
//                                    changeCount += 1;
//                                    //  Log.d(TAG, "onTouch: 向左换向" + changeCount);
//                                }
//                                // lastX = currentX;
//                            }
//                            //设置当前为向左滑动
//                            bol_directionRight = false;
//                        }
//
//                        //检测Y方向的滑动换向
//
//                        if (currentY - lastY > 0) {//此刻向下滑动
//                            if (!bol_directionDown) {//发生换向，重置参考点
//                                if (currentY - lastY > SLIDE_CHANGE_DIRECTION_THRESHOLD) {//滑动距离超过阈值，判定为已经换向
//                                    changeCount += 1;
//                                    // Log.d(TAG, "onTouch: 向下换向" + changeCount);
//                                }
//                                // lastY = currentY;
//                            }
//                            //设置当前为向下滑动
//                            bol_directionDown = true;
//
//                        } else if (currentY - lastY < 0) {//此刻向上边滑动
//
//                            if (bol_directionDown) {//发生换向，重置参考点
//                                if (Math.abs(currentY - lastY) > SLIDE_CHANGE_DIRECTION_THRESHOLD) {//滑动距离超过阈值，判定为已经换向
//                                    changeCount += 1;
//                                    //  Log.d(TAG, "onTouch: 向上换向" + changeCount);
//                                }
//                                // lastY = currentY;
//                            }
//                            //设置当前为向上滑动
//                            bol_directionDown = false;
//                        }
//                        lastX = currentX;
//                        lastY = currentY;
//                        long currentTime = motionEvent.getDownTime();
//                        if (changeCount >= 3 && !bol_hasClear && currentTime - startTime < 1500) {
//                            bol_hasClear = true;
//                            //检测到在晃动地图，清空地图上的附加物
//                            Log.d(TAG, "onTouch:检测到在晃动地图，清空地图上的附加物 ");
//                            mBaiduMap.clear();
//                        }
//
//                        break;
//
//                    case MotionEvent.ACTION_UP:
//                        if (isContinue) {
//                            handler.postDelayed(showPushTopic, postDelay);
//                        }
//                        if (!bol_hasClear) {
//                            bol_needNearbySearch = true;
//                            //根据滑动距离，判断是否需要根据当前位置去做附近搜索
//                            //在x方向上移动的距离大于屏幕宽度的2分之一或者在Y方向上移动的距离大于屏幕高度的3分之一
////                            Log.i(TAG, "onTouch: downX:"+downX+"currentX:"+currentX+"downY:"+downY+"currentY:"+currentY);
////                            if (Math.abs(currentX - downX) > screenWidth / 3 || Math.abs(currentY - downY) > screenHeight / 3) {
////                                //当前地图级别下1像素点对应的距离长度（米）
////                                float scalePerPixel = mBaiduMap.getScalePerPixel();
////                                //搜索半径
////                                int searchDistance = (int) (scalePerPixel * screenWidth / 2) / 1000;
////                                if (searchDistance < 5) {
////                                    searchDistance = 5;
////                                }
////                                Log.d(TAG, "搜索半径为searchDistance:" + searchDistance);
////                                if (lastCameraCenter != null) {
////                                    Log.i(TAG, "onTouch: lastCameraCenter：latitude " + lastCameraCenter.latitude + "longitude:" + lastCameraCenter.longitude);
////                                    nearbySearch(lastCameraCenter, searchDistance);
////                                } else {
////                                    Log.i(TAG, "onTouch: lastCameraCenter 为空");
////
////                                }
////                            }
//
//
//                        }
//                        bol_hasClear = false;
//                        bol_firstSlide = true;
//                        lastX = 0;
//                        lastY = 0;
//                        changeCount = 0;
//
//                }
//            }
//        });
//        mBaiduMap.setOnMapStatusChangeListener(new BaiduMap.OnMapStatusChangeListener() {
//            @Override
//            public void onMapStatusChangeStart(MapStatus mapStatus) {
//
//            }
//
//            @Override
//            public void onMapStatusChangeStart(MapStatus mapStatus, int i) {
//
//            }
//
//            @Override
//            public void onMapStatusChange(MapStatus mapStatus) {
//
//
//            }
//
//            @Override
//            public void onMapStatusChangeFinish(MapStatus mapStatus) {
//
//                slidell = mapStatus.target;
//                //地图移动了，改变罗盘模式为普通模式
//                android.graphics.Point slidePoint = mBaiduMap.getProjection().toScreenLocation(slidell);
//                android.graphics.Point llPoint = mBaiduMap.getProjection().toScreenLocation(ll);
//                if (slidePoint == null || llPoint == null) {
//                    return;
//                }
//                if ((Math.abs(slidePoint.x - llPoint.x) > screenWidth / 12 || Math.abs(slidePoint.y - llPoint.y) > screenHeight / 12))//
//                {
//                    if (mCurrentMode == MyLocationConfiguration.LocationMode.COMPASS) {
//                        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
//                        MapStatus mapStatu = new MapStatus.Builder(mBaiduMap.getMapStatus()).overlook(-45).build();
//
//                        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatu));
//                    }
//                    btnMapstatus.setBackgroundResource(R.drawable.tx_map_location);
//                    bol_location = true;
//                    setLocationIcon(null);
//                }
//
//            }
//        });
//        markerClickListener();
//    }
//
//    private void setLocationIcon(BitmapDescriptor maker) {
//
//        MyLocationConfiguration myLocationConfiguration = new MyLocationConfiguration(mCurrentMode, true, maker);
//
//        //, accuracyCircleFillColor, accuracyCircleStrokeColor
//        mBaiduMap.setMyLocationConfiguration(myLocationConfiguration);
//    }
//
//    public void receiveLocation(BDLocation location) {
//        //mapview 销毁后不做操作
//        if (location == null && mBaiduMap == null)
//            return;
//        // 构造定位数据
//        int mCurrentDirection = 0;
//        MyLocationData locData = new MyLocationData.Builder()
//                .accuracy(location.getRadius())
//                // 此处设置开发者获取到的方向信息，顺时针0-360
//                .direction(mCurrentDirection).latitude(location.getLatitude())
//                .longitude(location.getLongitude()).build();
//
////            BigDecimal bd = new BigDecimal((double) speed);
////            BigDecimal bd1 = bd.setScale(2, bd.ROUND_HALF_UP);
////取两位小数
//
//
//        double mCurrentLat = location.getLatitude();
//        double mCurrentLong = location.getLongitude();
//        ll = new com.baidu.mapapi.model.LatLng(mCurrentLat, mCurrentLong);
//        if (slidell == null) {
//            slidell = ll;
//        }
//
//        // Log.w("经纬度", mCurrentLat+"--"+mCurrentLong);
//        //  pt = new LatLng(mCurrentLat, mCurrentLong);
//        // 设置定位数据
//        //  if (location.get)
//
//        mBaiduMap.setMyLocationData(locData);
//        //创建定位光标
//        setLocationIcon(null);
//
//        if (isFirstLocation) {
//            isFirstLocation = false;
//            location(ll);
//            //  mLocationClient.stop();
//            if (mCurrentLat != mCurrentLatOld && mCurrentLat != 0.0) {
//                mCurrentLatOld = mCurrentLat;
//
//
//            }
//        }
//    }
//
//
//    void initDrawerLayout() {
//
//
//        mDrawerLayout.setScrimColor(Color.TRANSPARENT);
//        mDrawerLayout.addDrawerListener(new DrawerLayout.DrawerListener() {
//            @Override
//            public void onDrawerSlide(@NonNull View view, float v) {
//
//            }
//
//            @Override
//            public void onDrawerOpened(@NonNull View view) {
//                hideSoftKeyboard();
//                searchView.setVisibility(View.GONE);
//                searchView.onActionViewCollapsed();
//                closeSearchView();
//            }
//
//            @Override
//            public void onDrawerClosed(@NonNull View view) {
//                searchView.setVisibility(View.VISIBLE);
//
//            }
//
//            @Override
//            public void onDrawerStateChanged(int i) {
//
//            }
//        });
//    }
//
//
//    private void initSearchView() {
//        searchView = view.findViewById(R.id.search_view);
//        searchView.setSubmitButtonEnabled(true);
//        // searchView.setOnQueryTextListener(getQueryTextListener());
//        initSearchHistoryListView();
//        //这儿动态设置背景，不知道为什么，在布局文件里面设置了没有效果
//        searchView.setOnQueryTextFocusChangeListener(new View.OnFocusChangeListener() {
//            @Override
//            public void onFocusChange(View v, boolean hasFocus) {
////                if (hasFocus) {
////                    searchView.setBackground(new ColorDrawable(Color.WHITE));
////                    showSearchHistory();
////                    rl_search.setVisibility(View.VISIBLE);
////                } else {
////
////                }
//
//            }
//        });
//
//        searchView.setOnCloseListener(new SearchView.OnCloseListener() {
//            @Override
//            public boolean onClose() {
//                closeSearchView();
//
//
//                return false;
//            }
//        });
//        searchView.setOnSearchClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                searchView.setBackground(new ColorDrawable(Color.WHITE));
//                showSearchHistory();
//                rl_search.setVisibility(View.VISIBLE);
//            }
//        });
//
//        searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
//            @Override
//            public boolean onQueryTextSubmit(String et_localSearch) {
//                //把查询内容添加进搜索历史
//                if (!searchHistoryList.contains(et_localSearch)) {
//                    searchHistoryList.add(0, et_localSearch);
//                    PreferenceManager.getInstance().setCurrentUserSearchHistory(searchHistoryList);
//                    searchHistoryAdapter.notifyDataSetChanged();
//
//                }
//                //  aMapSearch(et_localSearch, null, "全国", Constant.AMAP_SAERCH_TYPE_LOCAL);
//                search(et_localSearch);
//                return false;
//            }
//
//            @Override
//            public boolean onQueryTextChange(String newText) {
//                //如果输入框没有内容，显示搜索历史
//                if (newText == null || newText.equals("")) {
//                    showSearchHistory();
//                }
//
//                //做搜索建议
//                return false;
//            }
//        });
//        ItemTouchHelper touchHelper = new ItemTouchHelper(new ItemTouchHelperCallBack());
//
//        touchHelper.attachToRecyclerView(rl_search);
//
//    }
//
//    void showSearchHistory() {
//        showSearchResult = false;
//        rl_search.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayout.VERTICAL, false));
//        rl_search.setAdapter(searchHistoryAdapter);
//    }
//
//    private void initSearchHistoryListView() {
//        List<String> currentUserSearchHistory = PreferenceManager.getInstance().getCurrentUserSearchHistory();
//        if (currentUserSearchHistory != null) {
//            searchHistoryList.addAll(currentUserSearchHistory);
//        }
//        searchHistoryAdapter = new SearchHistoryAdapter(getContext(), searchHistoryList);
//        searchHistoryAdapter.setSearchHistoryItemClickListener(new SearchHistoryAdapter.SearchHistoryItemClickListener() {
//            @Override
//            public void onItemClick(SearchHistoryAdapter.MyViewHolder viewHolder) {
//                hideSoftKeyboard();
//                search(searchHistoryList.get(viewHolder.getAdapterPosition()));
//                viewHolder.progressBar.setVisibility(View.VISIBLE);
//                // aMapSearch(searchHistoryList.get(position), null, "全国", Constant.AMAP_SAERCH_TYPE_LOCAL);
//            }
//        });
//
//    }
//
//    private void initContactListView() {
//        //getContactList();
//        // listView = view.findViewById(R.id.left_drawer);
//        //listView.getBackground().setAlpha(175);
//        contactListView = view.findViewById(R.id.contact_list_view);
//        contactListView.init(Helper.getInstance().getContactList());
//        contactListView.setListener(new ContactListView.InteractionListener() {
//            @Override
//            public void onContactDelete() {
//                ((MainActivity) getActivity()).updateUnreadLabel();//更新未读红点
//            }
//
//            @Override
//            public void addContact() {
//
//            }
//        });
////        adapter = new ExpandableAdapter(getActivity(), parentList, childMap);
////        adapter.setItemClickListener(new ExpandableAdapter.ItemClickListener() {
////            @Override
////            public void groupItemClick() {
////
////            }
////
////            @Override
////            public void childItemClick() {
////
////            }
////
////            @Override
////            public void childItemShowDialogClick(Contact contact) {
////                childViewGetMoreClick(contact);
////            }
////        });
//        //listView.setAdapter(adapter);
//        //listView.setLayoutParams(params);
//    }
//
//
//    @Override
//    public void onClick(View v) {
//        switch (v.getId()) {
//
//            case R.id.btn_map_status:
//
//
//                if (bol_location) //Math.abs(slidePoint.x - llPoint.x) > screenWidth / 4 || Math.abs(slidePoint.y - llPoint.y) > screenHeight / 4
//                {
//                    location(ll);
//                    bol_location = false;
//
//                    btnMapstatus.setBackgroundResource(R.drawable.tx_map_navigation_big);
//                    // slidell = ll;
//                } else {
//                    if (mCurrentMode == MyLocationConfiguration.LocationMode.COMPASS) {
//                        btnMapstatus.setBackgroundResource(R.drawable.tx_map_navigation_big);
//                        MapStatus mapStatus = new MapStatus.Builder(mBaiduMap.getMapStatus()).overlook(-45).rotate(90).build();
//                        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatus));
//                        mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
//                    } else {
//                        btnMapstatus.setBackgroundResource(R.drawable.compass);
//                        MapStatus mapStatus = new MapStatus.Builder(mBaiduMap.getMapStatus()).overlook(-45).build();
//                        mBaiduMap.animateMapStatus(MapStatusUpdateFactory.newMapStatus(mapStatus));
//                        mCurrentMode = MyLocationConfiguration.LocationMode.COMPASS;
//                    }
//                        setLocationIcon(null);
//
//                }
//                //  }
//                break;
//            case R.id.btn_publish:
//
//                startActivity(new Intent(getActivity(), PublishTopicActivity.class));
//
//                break;
//            case R.id.iv_topic_show_model_switch:
//                if (listener != null) {
//                    listener.onChangeFragment();
//                }
//                break;
//
//        }
//    }
//
//
//    private void markerClickListener() {
//        mBaiduMap.setOnMarkerClickListener(new BaiduMap.OnMarkerClickListener() {
//            @Override
//            public boolean onMarkerClick(final Marker marker) {
//                View viewInfoWindow = LayoutInflater.from(getActivity()).inflate(R.layout.baidu_maker_infowindow, null);
//                viewInfoWindow.getBackground().setAlpha(175);
//                TextView tv_name = viewInfoWindow.findViewById(R.id.tv_name);
//                TextView tv_address = viewInfoWindow.findViewById(R.id.tv_address);
//                TextView tv_time = viewInfoWindow.findViewById(R.id.tv_time);
//                ImageButton btn_chat = viewInfoWindow.findViewById(R.id.btn_chat);
//
//
//                InfoWindow mInfoWindow = new InfoWindow(viewInfoWindow, marker.getPosition(), -(int) (INFO_WINDOW_OFF_SET * density));//density 屏幕像素密度
//                Bundle bundle = marker.getExtraInfo();
//                final User targetUser = bundle.getParcelable(EaseConstant.EXTRA_TARGET_USER);
//                tv_name.setText(targetUser.getTitle());
//                tv_address.setText(targetUser.getArea());
//                SimpleDateFormat timeFormat = new SimpleDateFormat("yyyy/MM/dd HH:mm:ss");
//                tv_time.setText(timeFormat.format(targetUser.getCreated()));
//                btn_chat.setOnClickListener(new View.OnClickListener() {
//                    @Override
//                    public void onClick(View v) {
//                        startActivity(new Intent(getActivity(), ChatActivity.class).putExtra(EaseConstant.EXTRA_TARGET_USER_INFO, targetUser));
//                    }
//                });
//                mBaiduMap.showInfoWindow(mInfoWindow);
//                return true;
//
//            }
//        });
//    }
//
//    @NonNull
//    private View generateUserLocationView(User targetUser) {
//        View viewInfoWindow = LayoutInflater.from(getActivity()).inflate(R.layout.baidu_maker_infowindow, null);
//        viewInfoWindow.getBackground().setAlpha(175);
//        TextView tv_name = viewInfoWindow.findViewById(R.id.tv_name);
//        TextView tv_address = viewInfoWindow.findViewById(R.id.tv_address);
//        TextView tv_time = viewInfoWindow.findViewById(R.id.tv_time);
//        View btn_chat = viewInfoWindow.findViewById(R.id.btn_chat);
//        ImageView iv_avatar = viewInfoWindow.findViewById(R.id.iv_avatar);
//        ImageView iv_navigation = viewInfoWindow.findViewById(R.id.btn_navigation);
//        GlideApp.with(this).load(targetUser.getAvatar()).into(iv_avatar);
//        tv_name.setText(targetUser.getUsername());
//        tv_address.setText(targetUser.getArea());
//        tv_time.setText(DateUtils.getTimestampString(targetUser.getCreated()));
//        btn_chat.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startActivity(new Intent(getActivity(), ChatActivity.class).putExtra(EaseConstant.EXTRA_TARGET_USER_INFO, targetUser));
//            }
//        });
//        //  iv_navigation.setOnClickListener(v -> showSelectNaviDialog(targetUser.getLatLng().getLongitude(), targetUser.getLatLng().getLatitude(), targetUser.getArea()));
//        return viewInfoWindow;
//    }
//
//    @NonNull
//    private View generateTopicLocationView(Topic topic) {
//
//        View view = LayoutInflater.from(getContext()).inflate(R.layout.topic_infowindow_layout, null);
//        TextView tv_title = view.findViewById(R.id.tv_title);
//        //TextView tv_content = view.findViewById(R.id.tv_content);
//        ImageView iv_topicType = view.findViewById(R.id.iv_topic_type);
//        tv_title.setText(topic.getTitle());
//        // tv_content.setText(topic.getContent());
//
//        if (topic.getType() != null) {
//
//            switch (topic.getType()) {
//                case Constant.TOPIC_TYPE_LOST_PEOPLE:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_lost_person);
//                    break;
//                case Constant.TOPIC_TYPE_REWARD:
//                    iv_topicType.setImageResource(R.drawable.tx_reward_coin);
//                    break;
//                case Constant.TOPIC_TYPE_EXPOSE:
//                    //    tv_title.setTextColor(getResources().getColor(R.color.topic_type_expose_red));
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_expose_3);
//                    break;
//                case Constant.TOPIC_TYPE_FOUND:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_found);
//                    break;
//                case Constant.TOPIC_TYPE_GIFT:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_gift);
//                    break;
//                case Constant.TOPIC_TYPE_AUCTION:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_auction);
//                    break;
//                case Constant.TOPIC_TYPE_GOODS:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_goods);
//                    break;
//                case Constant.TOPIC_TYPE_SHOW:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_show);
//                    break;
//
//                case Constant.TOPIC_TYPE_AREA:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_area);
//                    break;
//
//                case Constant.TOPIC_TYPE_INDUSTRY:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_industry);
//                    break;
//
//                case Constant.TOPIC_TYPE_SCHOOL:
//                    iv_topicType.setImageResource(R.drawable.tx_topic_type_school_5);
//                    //   tv_title.setTextColor(getResources().getColor(R.color.topic_type_school_orange));
//
//                    break;
//
//                default:
//                    iv_topicType.setVisibility(View.GONE);
//
//            }
//        }
//        // InfoWindowView infoWindowView = new InfoWindowView(getContext(), searchResultList.get(position));
//        view.setOnClickListener(new View.OnClickListener() {
//            @Override
//            public void onClick(View v) {
//                startActivity(new Intent(getActivity(), TopicDetailsActivity.class).putExtra(Constant.EXTRA_INFO_TOPIC, topic)));
//            }
//        });
//        return view;
//    }
//
//    private void location(LatLng latLng) {
//
//        MapStatusUpdate u = MapStatusUpdateFactory
//                .newLatLng(latLng);
//        mBaiduMap.setMapStatus(u);
//    }
//
//
//    @Override
//    public void onMyLocationChange(GaodeLocationClient location) {
//
//
//        LatLng locationLatLon = new LatLng(location.getLatitude(), location.getLongitude());
//
//        Log.d(TAG, "定位成功");
//    }
//
////    @Override
////    public void onLocationChanged(AMapLocation aMapLocation) {
////
////        //mapview 销毁后不做操作
////        if (aMapLocation == null && mBaiduMap == null)
////            return;
////        // 构造定位数据
////        int mCurrentDirection = 0;
////
////        double mCurrentLat = aMapLocation.getLatitude();
////        double mCurrentLong = aMapLocation.getLongitude();
////        ll = new LatLng(mCurrentLat, mCurrentLong);
////        if (slidell == null) {
////            slidell = ll;
////        }
////
////        // Log.w("经纬度", mCurrentLat+"--"+mCurrentLong);
////        //  pt = new LatLng(mCurrentLat, mCurrentLong);
////        // 设置定位数据
////        //  if (location.get)
////
////      location(new LatLng(mCurrentLat,mCurrentLong));
////        //创建定位光标
////
////        if (isFirstLocation) {
////            isFirstLocation = false;
////            location(ll);
////            //  mLocationClient.stop();
////            if (mCurrentLat != mCurrentLatOld && mCurrentLat != 0.0) {
////                mCurrentLatOld = mCurrentLat;
////
////
////            }
////        }
////    }
//
//
//    @Override
//    public void onHiddenChanged(boolean hidden) {
//        super.onHiddenChanged(hidden);
//        this.hidden = hidden;
//        if (!hidden) {
//            isContinue = true;
//            handler.post(showPushTopic);
//
//        } else {//当隐藏的时候，如果显示推送topic的循环还在继续，中断
//            handler.removeCallbacks(showPushTopic);
//            isContinue = false;
//        }
//    }
//
//
//    @Override
//    public void onResume() {
//        super.onResume();
//
//        bMapView.onResume();
//
//    }
//
//    @Override
//    public void onPause() {
//        super.onPause();
//
//        bMapView.onPause();
//
//
//    }
//
//    @Override
//    public void onDestroy() {
//        super.onDestroy();
//        bMapView.onDestroy();
//
//    }
//
//
//    public void refresh() {
//        // getContactList();
//        // updateNoticeUnreadText();
//        contactListView.refresh(Helper.getInstance().getContactList());
//        //adapter.notifyDataSetChanged();
//    }
//
//
//    public void createBaiDuMaker(final Intent intent) {
//        final User targetUser = intent.getExtras().getParcelable(EaseConstant.EXTRA_TARGET_USER);
//        if (targetUser == null) {
//            return;
//        }
//        final LatLng latLng = new LatLng(targetUser.getLatLng().getLatitude(), targetUser.getLatLng().getLongitude());
////        GlideApp.with(context).load(targetUser.getAvatar()).override((int) (MAKER_HEIGHT * dm.density), (int) (MAKER_HEIGHT * dm.density))
////
////                .error(R.drawable.tx_default_avatar)
////                .into(simpleTarget1);
//        RequestOptions options = new RequestOptions()
//                .error(R.drawable.tx_default_avatar)
//
//                .diskCacheStrategy(DiskCacheStrategy.ALL)
//                .override((int) (MAKER_HEIGHT * density), (int) (MAKER_HEIGHT * density));
//
//        Glide.with(this).asBitmap().load(targetUser.getAvatar()).apply(options).into(new SimpleTarget<Bitmap>() {
//            @Override
//            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
//                MarkerOptions markerOptions = new MarkerOptions()
//                        .position(latLng)
//                        .icon(BitmapDescriptorFactory.fromBitmap(resource))
//                        .zIndex(0)
//                        .draggable(true)
//                        .animateType(MarkerOptions.MarkerAnimateType.grow);
//
//                mMarker = (Marker) mBaiduMap.addOverlay(markerOptions);
//                mDrawerLayout.closeDrawer(listView);
//                if (mCurrentMode == MyLocationConfiguration.LocationMode.COMPASS) {
//                    mCurrentMode = MyLocationConfiguration.LocationMode.NORMAL;
//                }
//                mMarker.setExtraInfo(intent.getExtras());
//                location(latLng);
//            }
//        });
//    }
//
//    private SearchView.OnQueryTextListener getQueryTextListener() {
//        SearchView.OnQueryTextListener listener = new SearchView.OnQueryTextListener() {
//            @Override
//            public boolean onQueryTextSubmit(String et_localSearch) {
//                //开始搜索
//                search(et_localSearch);
//                // aMapSearch(et_localSearch, null, "全国", Constant.AMAP_SAERCH_TYPE_LOCAL);
//                return false;
//            }
//
//            @Override
//            public boolean onQueryTextChange(String newText) {
//                //可以做搜索建议
//                return false;
//            }
//        };
//        return listener;
//    }
//
//    private void search(String et_localSearch) {
//        Map<String, Object> info = new HashMap<>();
//        info.put("queryContent", et_localSearch);
//        RetrofitManager.getInstance().createRequest(TopicService.class)
//                .search(info)
//                .enqueue(new Callback<CommonResult>() {
//                    @Override
//                    public void onResponse(Call<CommonResult> call, Response<CommonResult> response) {
//                        CommonResult result = response.body();
//                        if (!response.isSuccessful() || result == null) {
//                            Log.e(TAG, "ES搜索失败：" + response.message());
//                            return;
//                        }
//
//                        if (result.isError()) {
//                            Log.e(TAG, "ES搜索失败：" + result.getMsg());
//                            return;
//                        }
//                        showSearchResult();
//
//                        JSONObject jsonObject = (JSONObject) result.getData();
//                        Log.d(TAG, "ES搜索完成" + jsonObject);
//                        List<Topic> resultsList = JSONObject.parseArray(jsonObject.getString("hits"), Topic.class);
//                        searchResultList.addAll(resultsList);
//                        searchResultAdapter.notifyDataSetChanged();
//                        //  showToast("查询成功");
//                    }
//
//                    @Override
//                    public void onFailure(Call<CommonResult> call, Throwable t) {
//                        Log.e(TAG, "ES搜索失败：" + t.getMessage());
//                    }
//                });
//    }
//
//
//    private void showSearchResult() {
//        showSearchResult = true;
//        if (searchResultAdapter == null) {
//            searchResultAdapter = new SearchResultAdapter(getContext(), this, searchResultList);
//            searchResultAdapter.setSearchResultItemClickListener(new SearchResultAdapter.SearchResultItemClickListener() {
//                @Override
//                public void onItemClick(final int position, Topic topic) {
//
//                    // startActivity(new Intent(getContext(), TopicDetailsActivity.class).putExtra(Constant.EXTRA_INFO_TOPIC, searchResultList.get(position)));
//                    // Topic topic = searchResultList.get(position);
//                    LatLng latLng = new LatLng(topic.getLocation().getLatitude(), topic.getLocation().getLongitude());
//                    MarkerOptions markerOptions = new MarkerOptions()
//                            .position(latLng)
//                            .zIndex(0)
//                            .draggable(true)
//                            .animateType(MarkerOptions.MarkerAnimateType.grow);
//
//                    mMarker = (Marker) mBaiduMap.addOverlay(markerOptions);
//
//                    View view = generateTopicLocationView(topic);
//                    InfoWindow mInfoWindow = new InfoWindow(view, latLng, -(int) (INFO_WINDOW_OFF_SET * density));//density 屏幕像素密度
//                    location(latLng);
//                    mBaiduMap.showInfoWindow(mInfoWindow);
//                    // rl_search.setVisibility(View.GONE);
//                    searchView.clearFocus();
//                }
//
//                @Override
//                public void onAddContact(User userInfo, String reason) {
//                    hideSoftKeyboard();
//                    contactListView.addContact(userInfo, reason);
//                }
//            });
//        }
//        //重新设置dapter的时候，需要重新设置新的 LayoutManager
//        rl_search.setLayoutManager(new LinearLayoutManager(getContext(), LinearLayout.VERTICAL, false));
//        rl_search.setAdapter(searchResultAdapter);
//        searchResultList.clear();
//    }
//
//    private void showProgressBar(boolean isShowProgressBar) {
//        if (isShowProgressBar && !progressBar.isShown()) {
//            progressBar.setVisibility(View.VISIBLE);
//        } else if (!isShowProgressBar && progressBar.isShown()) {
//            progressBar.setVisibility(View.GONE);
//        }
//    }
//
//    public void createUserLocationMaker(Intent intent) {
//
//        final User targetUser = intent.getExtras().getParcelable(EaseConstant.EXTRA_TARGET_USER);
//        if (targetUser == null) {
//            return;
//        }
//        com.mytx.pojo.LatLng latLng1 = targetUser.getLatLng();
//        if (latLng1.getLatitude() == 0.0 || latLng1.getLongitude() == 0.0) {
//            return;
//        }
//        final LatLng latLng = new LatLng(targetUser.getLatLng().getLatitude(), targetUser.getLatLng().getLongitude());
////        GlideApp.with(context).load(targetUser.getAvatar()).override((int) (MAKER_HEIGHT * dm.density), (int) (MAKER_HEIGHT * dm.density))
////
////                .error(R.drawable.tx_default_avatar)
////                .into(simpleTarget1);
//        RequestOptions options = new RequestOptions()
//                .error(R.drawable.tx_default_avatar)
//                .diskCacheStrategy(DiskCacheStrategy.ALL)
//                .override((int) (MAKER_HEIGHT * density), (int) (MAKER_HEIGHT * density));
//
//        Glide.with(this).asBitmap().load(targetUser.getAvatar()).apply(options).into(new SimpleTarget<Bitmap>() {
//            @Override
//            public void onResourceReady(@NonNull Bitmap resource, @Nullable Transition<? super Bitmap> transition) {
//            }
//        });
//        MarkerOptions markerOptions = new MarkerOptions()
//                .position(latLng)
//                .zIndex(0)
//                .draggable(false);
//
//        mMarker = (Marker) mBaiduMap.addOverlay(markerOptions);
//        mDrawerLayout.closeDrawer(contactListView);
//        View view = generateUserLocationView(targetUser);
//        InfoWindow mInfoWindow = new InfoWindow(view, latLng, -(int) (INFO_WINDOW_OFF_SET * density));
//        mBaiduMap.showInfoWindow(mInfoWindow);
//        location(latLng);
//
//    }
//
//    public void receivePushTopic(Intent intent) {
//        Topic topic = intent.getParcelableExtra(Constant.EXTRA_INFO_TOPIC);
//        Date date = topic.getUpdated() != null ? topic.getUpdated() : topic.getCreated();
//        Calendar calendar = Calendar.getInstance();
//        calendar.add(Calendar.DAY_OF_MONTH, -2);
//        Date twoDaysAgo = calendar.getTime();
//
//        //如果主题的创建或者更新时间在2天以前，并且有收到的推送主题目前还有超过30条未展示，就丢弃
//        if (twoDaysAgo.after(date) && pushTopicList.size() > 30) {
//            return;
//        }
//        pushTopicList.add(topic);
//        //当当前fragment没有隐藏，且循环已经中断的情况下，调用handler 立即显示当前收到的推送topic
//        if (!hidden && !isContinue) {
//            handler.post(showPushTopic);
//        }
//    }
//
//
//    public class ItemTouchHelperCallBack extends ItemTouchHelper.Callback {
//        @Override
//        public int getMovementFlags(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder) {
//            if (showSearchResult) {
//                return ItemTouchHelper.ACTION_STATE_IDLE;
//            }
//            if (viewHolder.getAdapterPosition() == searchHistoryAdapter.getItemCount() - 1) {
//                return ItemTouchHelper.ACTION_STATE_IDLE;
//            }
//            int dragFlags = ItemTouchHelper.UP | ItemTouchHelper.DOWN;
//            int swipeFlags = ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT;
//            return makeMovementFlags(dragFlags, swipeFlags);
//        }
//
//        @Override
//        public boolean onMove(RecyclerView recyclerView, RecyclerView.ViewHolder viewHolder, RecyclerView.ViewHolder target) {
//            return false;
//        }
//
//        @Override
//        public void onSwiped(RecyclerView.ViewHolder viewHolder, int direction) {
//            Log.d(TAG, "onSwiped: 滑动删除，，，，");
//            searchHistoryAdapter.removeSearchHistory(viewHolder.getAdapterPosition());
//        }
//    }
//
//    public boolean onBackClick() {
//
//        if (!searchView.isFocused() && rl_search.isShown()) {
//            searchView.onActionViewCollapsed();
//            closeSearchView();
//            return true;
//        }
//        return false;
//    }
//
//    void closeSearchView() {
//        searchView.setBackground(new ColorDrawable(Color.TRANSPARENT));
//        rl_search.setVisibility(View.GONE);
//    }
//
//    public void setListener(MainActivity.ChangeFragmentListener listener) {
//        this.listener = listener;
//    }
//
//    private void showSingleMarker(Topic topic) {
//
//        if (topic == null) {
//            return;
//        }
//        LatLng latLng = new LatLng(topic.getLocation().getLatitude(), topic.getLocation().getLongitude());
//        MarkerOptions markerOption = new MarkerOptions()
//                .position(latLng)
//                .title(topic.getTitle())
//
//                .draggable(true);
//
//        mMarker = (Marker) mBaiduMap.addOverlay(markerOption);
//        InfoWindow mInfoWindow = new InfoWindow(generateTopicLocationView(topic), latLng, -(int) (INFO_WINDOW_OFF_SET * density));
//        mBaiduMap.showInfoWindow(mInfoWindow);
//        location(latLng);
//    }
//
//
//}
//
